/**
 * 
 */
package hu.gbalage.owlforms.internal.derived;

import java.net.URI;

import hu.gbalage.owlforms.api.Field;
import hu.gbalage.owlforms.api.Form;
import hu.gbalage.owlforms.api.data.FormData;

/**
 * @author balage
 *
 */
public class SzoctamCalc implements IDerivedCalculator {

	public static final URI szocpont = URI.create("http://owlforms.gbalage.hu/core.owl#szocpont");
	
	public static final URI[] fields = new URI[]{
		URI.create("http://owlforms.gbalage.hu/example/szoctam_hallgato.owl#has_EgyForeEsoJovedelem"),
		URI.create("http://owlforms.gbalage.hu/example/szoctam_hallgato.owl#has_Eltartottak")
	};
	
	/* (non-Javadoc)
	 * @see hu.gbalage.owlforms.internal.derived.IDerivedCalculator#calculate(hu.gbalage.owlforms.api.data.FormData, hu.gbalage.owlforms.api.Field)
	 */
	public String calculate(FormData on, Field field) {
		
		int osszeg = 0;
		
		Form form = on.getForm();
		
		for(URI f : fields){
			FormData d = on.getData(form.getField(f)).listValues().get(0).asCompositeValue().getCompositeData();
			String value = d.getData(d.getForm().getField(szocpont)).listValues().get(0).asPrimitiveValue().getValue();
			try{
				osszeg += Integer.parseInt(value);
			}catch(NumberFormatException e){
				e.printStackTrace();
			}
		}
		
		return osszeg+"";
	}

}
